1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
package org.apache.geronimo.ews.ws4j2ee.toWs;
|
18
|
|
|
19
|
|
import org.apache.axis.wsdl.fromJava.Emitter;
|
20
|
|
import org.apache.commons.logging.Log;
|
21
|
|
import org.apache.commons.logging.LogFactory;
|
22
|
|
import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
|
23
|
|
import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
|
24
|
|
import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.WebContext;
|
25
|
|
import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFContext;
|
26
|
|
import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFPortComponent;
|
27
|
|
import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFWebserviceDescription;
|
28
|
|
import org.apache.geronimo.ews.ws4j2ee.module.Module;
|
29
|
|
import org.apache.geronimo.ews.ws4j2ee.toWs.impl.Ws4J2eeFactoryImpl;
|
30
|
|
import org.apache.geronimo.ews.ws4j2ee.utils.FileUtils;
|
31
|
|
import org.apache.geronimo.ews.ws4j2ee.utils.MiscFactory;
|
32
|
|
|
33
|
|
import java.io.File;
|
34
|
|
import java.io.FileNotFoundException;
|
35
|
|
import java.io.FileOutputStream;
|
36
|
|
import java.io.IOException;
|
37
|
|
import java.io.InputStream;
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
public class Ws4J2ee implements Generator {
|
43
|
|
protected static Log log =
|
44
|
|
LogFactory.getLog(Ws4J2ee.class.getName());
|
45
|
|
private J2EEWebServiceContext wscontext;
|
46
|
|
private boolean verbose = false;
|
47
|
|
private Ws4J2eeDeployContext clparser;
|
48
|
|
private WSCFPortComponent port;
|
49
|
|
private ClassLoader classloader;
|
50
|
|
|
51
|
|
private Module module;
|
52
|
|
private String wsdlImplFilename;
|
53
|
|
|
54
|
|
private InputStream wscffile;
|
55
|
|
private InputStream ejbddin;
|
56
|
|
private InputStream webddin;
|
57
|
|
private InputStream wsdlFile;
|
58
|
|
private InputStream jaxrpcmappingFile;
|
59
|
|
private String ejbLink;
|
60
|
|
private Emitter emitter;
|
61
|
|
private Ws4J2eeFactory factory;
|
62
|
|
|
63
|
11
|
public Ws4J2ee(Ws4J2eeDeployContext doployContext, Emitter emitter)
|
64
|
|
throws GenerationFault {
|
65
|
11
|
if (emitter == null) {
|
66
|
0
|
this.emitter = new Emitter();
|
67
|
|
} else {
|
68
|
11
|
this.emitter = emitter;
|
69
|
|
}
|
70
|
11
|
this.clparser = doployContext;
|
71
|
|
|
72
|
11
|
prepareContext();
|
73
|
|
|
74
|
11
|
parseCLargs();
|
75
|
|
}
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
11
|
public void generate() throws GenerationFault {
|
83
|
11
|
try {
|
84
|
|
|
85
|
11
|
WSCFWebserviceDescription wscfwsdis = parseTheWSCF();
|
86
|
11
|
populateWebserviceInfo(wscfwsdis);
|
87
|
11
|
pareseJ2eeModule();
|
88
|
11
|
checkAndGenerateWsdlAndMapping(wscfwsdis);
|
89
|
11
|
Ws4J2eeEmitter ws4j2eeEmitter = new Ws4J2eeEmitter(wscontext);
|
90
|
11
|
ws4j2eeEmitter.emmit();
|
91
|
|
} finally {
|
92
|
11
|
cleanup();
|
93
|
|
}
|
94
|
|
}
|
95
|
|
|
96
|
11
|
private void prepareContext() {
|
97
|
11
|
factory = new Ws4J2eeFactoryImpl();
|
98
|
11
|
this.wscontext = factory.getContextFactory().getJ2EEWsContext(false);
|
99
|
11
|
this.wscontext.setFactory(factory);
|
100
|
11
|
this.wscontext.setMiscInfo(factory.getContextFactory().createMiscInfo(clparser.getProperties()));
|
101
|
11
|
wscontext.getMiscInfo().setVerbose(verbose);
|
102
|
|
}
|
103
|
|
|
104
|
11
|
private void parseCLargs() throws GenerationFault {
|
105
|
11
|
module = clparser.getModule();
|
106
|
11
|
classloader = module.getClassLoaderWithPackageLoaded();
|
107
|
|
|
108
|
11
|
wscontext.getMiscInfo().setClassloader(classloader);
|
109
|
11
|
wscontext.getMiscInfo().setOutputPath(clparser.getOutPutLocation());
|
110
|
11
|
wscontext.getMiscInfo().setImplStyle(clparser.getImplStyle());
|
111
|
11
|
wscontext.getMiscInfo().setTargetJ2EEContainer(clparser.getContanier());
|
112
|
11
|
wscontext.getMiscInfo().setCompile(clparser.isCompile());
|
113
|
11
|
wsdlImplFilename = clparser.getWsdlImplFilename();
|
114
|
11
|
this.wscffile = module.getWscfFile();
|
115
|
11
|
ejbddin = module.getEjbJarfile();
|
116
|
11
|
webddin = module.getWebddfile();
|
117
|
11
|
wscontext.getMiscInfo().setWsconffile(MiscFactory.getInputFile(this.wscffile));
|
118
|
11
|
wscontext.getMiscInfo().setClassPathElements(module.getClassPathElements());
|
119
|
|
}
|
120
|
|
|
121
|
11
|
private WSCFWebserviceDescription parseTheWSCF() throws GenerationFault {
|
122
|
11
|
WSCFContext wscfcontext =
|
123
|
|
factory.getParserFactory().parseWSCF(wscontext, this.wscffile);
|
124
|
11
|
wscontext.setWSCFContext(wscfcontext);
|
125
|
11
|
if (verbose)
|
126
|
0
|
log.info(wscffile + " parsed ..");
|
127
|
11
|
WSCFWebserviceDescription[] wscfwsdiss =
|
128
|
|
wscontext.getWSCFContext().getWebServicesDescription();
|
129
|
|
|
130
|
11
|
if (wscfwsdiss == null || wscfwsdiss.length == 0)
|
131
|
0
|
throw new UnrecoverableGenerationFault("no webservice discription "
|
132
|
|
+ "found in the webservices.xml file");
|
133
|
11
|
wscontext.getWSCFContext().setWscfdWsDescription(wscfwsdiss[0]);
|
134
|
11
|
return wscfwsdiss[0];
|
135
|
|
}
|
136
|
|
|
137
|
11
|
private void generateTheWSDLfile() throws GenerationFault {
|
138
|
11
|
Generator wsdlgen
|
139
|
|
= factory.getGenerationFactory().createWSDLGenerator(wscontext, emitter, clparser);
|
140
|
11
|
wsdlgen.generate();
|
141
|
|
}
|
142
|
|
|
143
|
|
|
144
|
|
|
145
|
|
|
146
|
11
|
private void generateTheJaxrpcmappingFile() throws GenerationFault {
|
147
|
|
|
148
|
11
|
if (verbose)
|
149
|
0
|
log.info("genarating jaxrpc-mapper.xml ..............");
|
150
|
11
|
Generator jaxrpcfilegen = factory.getGenerationFactory()
|
151
|
|
.createJaxrpcMapperGenerator(wscontext);
|
152
|
11
|
jaxrpcfilegen.generate();
|
153
|
|
}
|
154
|
|
|
155
|
8
|
private void parseEJBModule() throws GenerationFault {
|
156
|
8
|
try {
|
157
|
8
|
File file = null;
|
158
|
8
|
if (ejbddin != null) {
|
159
|
8
|
EJBContext ejbcontext = factory.getParserFactory()
|
160
|
|
.parseEJBDDContext(wscontext, ejbddin);
|
161
|
8
|
wscontext.setEJBDDContext(ejbcontext);
|
162
|
8
|
ejbddin.close();
|
163
|
8
|
checkForImplBean(ejbcontext.getImplBean());
|
164
|
|
} else {
|
165
|
0
|
throw new GenerationFault("ejb-jar.xml file file does not exsits");
|
166
|
|
}
|
167
|
|
} catch (IOException e) {
|
168
|
0
|
log.error(e);
|
169
|
0
|
throw GenerationFault.createGenerationFault(e);
|
170
|
|
}
|
171
|
|
}
|
172
|
|
|
173
|
3
|
public void parseWebModule() throws GenerationFault {
|
174
|
3
|
wscontext.getMiscInfo().setImplwithEJB(false);
|
175
|
3
|
if (webddin != null) {
|
176
|
3
|
WebContext webcontext = factory.getParserFactory().parseWebDD(wscontext, webddin);
|
177
|
3
|
wscontext.setWebDDContext(webcontext);
|
178
|
3
|
checkForImplBean(webcontext.getServletClass());
|
179
|
|
} else {
|
180
|
0
|
throw new GenerationFault("web.xml file does not exsits");
|
181
|
|
}
|
182
|
|
}
|
183
|
|
|
184
|
11
|
private void checkForImplBean(String implBean) {
|
185
|
|
|
186
|
|
|
187
|
11
|
if (implBean == null) {
|
188
|
0
|
wscontext.getMiscInfo().setImplAvalible(false);
|
189
|
|
} else {
|
190
|
11
|
try {
|
191
|
11
|
Class.forName(implBean, true, classloader);
|
192
|
|
} catch (ClassNotFoundException e) {
|
193
|
3
|
wscontext.getMiscInfo().setImplAvalible(false);
|
194
|
|
} catch (java.lang.NoClassDefFoundError e) {
|
195
|
0
|
wscontext.getMiscInfo().setImplAvalible(false);
|
196
|
|
}
|
197
|
|
}
|
198
|
|
}
|
199
|
|
|
200
|
11
|
private void populateWebserviceInfo(WSCFWebserviceDescription wscfwsdis) {
|
201
|
11
|
wscontext.getWSCFContext().setWscfdWsDescription(wscfwsdis);
|
202
|
11
|
wscontext.getMiscInfo().setSEIExists(true);
|
203
|
11
|
WSCFPortComponent[] ports = wscfwsdis.getPortComponent();
|
204
|
|
|
205
|
11
|
if (ports == null || ports.length == 0)
|
206
|
0
|
throw new UnrecoverableGenerationFault("no port discription"
|
207
|
|
+ " found in the webservices.xml file");
|
208
|
11
|
this.port = ports[0];
|
209
|
11
|
wscontext.getWSCFContext().setWscfport(port);
|
210
|
11
|
this.ejbLink = port.getServiceImplBean().getEjblink();
|
211
|
11
|
String seiName = port.getServiceEndpointInterface();
|
212
|
11
|
wscontext.getMiscInfo().setJaxrpcSEI(seiName);
|
213
|
11
|
wscontext.getMiscInfo().setHandlers(port.getHandlers());
|
214
|
|
}
|
215
|
|
|
216
|
11
|
private void pareseJ2eeModule() throws GenerationFault {
|
217
|
11
|
if (ejbLink != null) {
|
218
|
8
|
wscontext.getMiscInfo().setJ2eeComponetLink(ejbLink);
|
219
|
8
|
wscontext.getMiscInfo().setImplwithEJB(true);
|
220
|
8
|
parseEJBModule();
|
221
|
|
} else {
|
222
|
3
|
wscontext.getMiscInfo().setJ2eeComponetLink(port.getServiceImplBean().getServletlink());
|
223
|
3
|
wscontext.getMiscInfo().setImplwithEJB(false);
|
224
|
3
|
parseWebModule();
|
225
|
|
}
|
226
|
|
}
|
227
|
|
|
228
|
11
|
private void checkAndGenerateWsdlAndMapping(WSCFWebserviceDescription wscfwsdis)
|
229
|
|
throws GenerationFault {
|
230
|
11
|
try {
|
231
|
11
|
String wsdlFilename = wscfwsdis.getWsdlFile();
|
232
|
11
|
String jaxrpcMappingFileName = wscfwsdis.getJaxrpcMappingFile();
|
233
|
11
|
this.wsdlFile = module.findFileInModule(wsdlFilename);
|
234
|
11
|
if (this.wsdlFile == null) {
|
235
|
11
|
String wsdlabsoluteFile = wscontext.getMiscInfo().getOutPutPath() + "/" + wsdlFilename;
|
236
|
11
|
wscontext.getMiscInfo().setWsdlFile(MiscFactory.getInputFile(wsdlabsoluteFile));
|
237
|
11
|
File jaxrpcfile = new File(wscontext.getMiscInfo().getOutPutPath() + "/" + jaxrpcMappingFileName);
|
238
|
11
|
wscontext.getMiscInfo().setJaxrpcfile(MiscFactory.getInputFile(jaxrpcfile.getAbsolutePath()));
|
239
|
11
|
generateTheWSDLfile();
|
240
|
11
|
generateTheJaxrpcmappingFile();
|
241
|
11
|
wscontext.getMiscInfo().setSEIExists(true);
|
242
|
|
} else {
|
243
|
0
|
File file = new File(wscontext.getMiscInfo().getOutPutPath() + "/" + wsdlFilename);
|
244
|
0
|
file.getParentFile().mkdirs();
|
245
|
0
|
FileUtils.copyFile(wsdlFile, new FileOutputStream(file));
|
246
|
0
|
wscontext.getMiscInfo().setWsdlFile(MiscFactory.getInputFile(file.getAbsolutePath()));
|
247
|
0
|
jaxrpcmappingFile = module.findFileInModule(jaxrpcMappingFileName);
|
248
|
0
|
file = new File(wscontext.getMiscInfo().getOutPutPath() + "/" + jaxrpcMappingFileName);
|
249
|
0
|
file.getParentFile().mkdirs();
|
250
|
0
|
FileUtils.copyFile(jaxrpcmappingFile, new FileOutputStream(file));
|
251
|
0
|
if (jaxrpcmappingFile == null) {
|
252
|
0
|
throw new GenerationFault("if the wsdlfile avalible the jaxrpcmapping file must be avalible");
|
253
|
|
} else {
|
254
|
0
|
wscontext.getMiscInfo().setJaxrpcfile(MiscFactory.getInputFile(file.getAbsolutePath()));
|
255
|
|
}
|
256
|
0
|
wscontext.getMiscInfo().setSEIExists(false);
|
257
|
|
}
|
258
|
|
} catch (FileNotFoundException e) {
|
259
|
0
|
log.error(e);
|
260
|
0
|
throw GenerationFault.createGenerationFault(e);
|
261
|
|
}
|
262
|
|
}
|
263
|
|
|
264
|
11
|
public void cleanup() throws GenerationFault {
|
265
|
11
|
try {
|
266
|
11
|
wscffile.close();
|
267
|
11
|
if (ejbddin != null) {
|
268
|
9
|
ejbddin.close();
|
269
|
|
}
|
270
|
11
|
if (webddin != null) {
|
271
|
5
|
webddin.close();
|
272
|
|
}
|
273
|
11
|
if (jaxrpcmappingFile != null) {
|
274
|
0
|
jaxrpcmappingFile.close();
|
275
|
|
}
|
276
|
11
|
if (wsdlFile != null) {
|
277
|
0
|
wsdlFile.close();
|
278
|
|
}
|
279
|
|
} catch (Exception e) {
|
280
|
0
|
log.error(e);
|
281
|
0
|
throw GenerationFault.createGenerationFault(e);
|
282
|
|
}
|
283
|
|
}
|
284
|
|
|
285
|
|
|
286
|
|
|
287
|
|
|
288
|
|
|
289
|
|
|
290
|
|
|
291
|
|
|
292
|
|
|
293
|
|
|
294
|
|
|
295
|
|
|
296
|
|
|
297
|
|
|
298
|
|
|
299
|
11
|
public static void main(String[] args) throws Exception {
|
300
|
11
|
Ws4J2ee gen = null;
|
301
|
11
|
Emitter emitter = new Emitter();
|
302
|
11
|
Ws4J2eeDeployContext deployContext = new Ws4J2eeServerCLOptionParser(args, emitter);
|
303
|
11
|
gen = new Ws4J2ee(deployContext, emitter);
|
304
|
11
|
gen.generate();
|
305
|
|
}
|
306
|
|
}
|
307
|
|
|